<script type="application/ld+json">
  {%- liquid
    if product.selected_or_first_available_variant.featured_media
      assign seo_media = product.selected_or_first_available_variant.featured_media
    else
      assign seo_media = product.featured_media
    endif
  -%}
  {
    "@context": "http://schema.org/",
    "@type": "Product",
    "name": {{ product.title | json }},
    "url": {{ request.origin | append: product.url | json }},
    {%- if seo_media %}
    "image": [
      {{ seo_media | image_url: width: seo_media.preview_image.width | prepend: "https:" | json }}
    ],
    {%- endif %}
    "description": {{ product.description | strip_html | json }},
    {%- if product.selected_or_first_available_variant.sku != blank %}
    "sku": {{ product.selected_or_first_available_variant.sku | json }},
    {%- endif %}
    "brand": {
      "@type": "Brand",
      "name": {{ product.vendor | json }}
    },
    "offers": [
    {%- for variant in product.variants %}
      {
        "@type" : "Offer",
        {%- if variant.sku != blank %}
        "sku": {{ variant.sku | json }},
        {%- endif %}
        {%- if variant.barcode.size == 12 -%}
        "gtin12": {{ variant.barcode }},
        {%- endif %}
        {%- if variant.barcode.size == 13 -%}
        "gtin13": {{ variant.barcode }},
        {%- endif %}
        {%- if variant.barcode.size == 14 -%}
        "gtin14": {{ variant.barcode }},
        {%- endif %}
        "availability" : "http://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
        "price" : {{ variant.price | divided_by: 100.00 | json }},
        "priceCurrency" : {{ cart.currency.iso_code | json }},
        "url" : {{ request.origin | append: variant.url | json }}
      }{% unless forloop.last %},{% endunless %}
    {%- endfor -%}
    ]
  }
</script>
